package com.campus.common.recharge.service.impl;

import com.campus.common.recharge.entity.RechargeRecords;
import com.campus.common.recharge.entity.vo.RechageStaticFinalVO;
import com.campus.common.recharge.entity.vo.RechargeStatictVO;
import com.campus.common.recharge.mapper.RechargeRecordsMapper;
import com.campus.common.recharge.service.IRechargeRecordsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 充值表，用于存储充值信息 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-11-29
 */
@Service
public class RechargeRecordsServiceImpl extends ServiceImpl<RechargeRecordsMapper, RechargeRecords> implements IRechargeRecordsService {

    @Override
    public Result insertRechargeRecords(RechargeRecords rechargeRecords) {
        this.save(rechargeRecords);
        return Result.success();
    }

    @Override
    public Result getRechargeStatic() {

        List<RechargeStatictVO> list = this.baseMapper.getStatic();
        List<RechageStaticFinalVO> finalList = list.stream().map(item -> {
            RechageStaticFinalVO vo = new RechageStaticFinalVO();
            vo.setName(item.getType());
            vo.setData(item.getData());
            return vo;
        }).toList();
        return Result.success(finalList);
    }
}
